package com.neborosoft.android.gui.views;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import com.neborosoft.FlyingDog.R;

/**
 * Created with IntelliJ IDEA.
 * User: CM
 * Date: 03.11.12
 * Time: 22:23
 * To change this template use File | Settings | File Templates.
 */
public class HighlightableLinearLayout extends LinearLayout{
    private boolean isHighlighted = false;

    public boolean isHighlighted() {
        return isHighlighted;
    }

    public void setHighlighted(boolean highlighted) {
        isHighlighted = highlighted;
        invalidate();
        refreshDrawableState();
    }

    public HighlightableLinearLayout(Context context, AttributeSet attrs) {
        super(context, attrs);

        TypedArray array = context.obtainStyledAttributes(attrs,R.styleable.LayoutRadioButton);
        isHighlighted = array.getBoolean(R.styleable.LayoutRadioButton_is_selected,false);
        array.recycle();
    }

    @Override
    protected int[] onCreateDrawableState(int extraSpace) {
        int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
        if(isHighlighted){
            int[] additionalStates = {R.attr.is_selected};
            drawableState = mergeDrawableStates(drawableState,additionalStates);
        }
        return drawableState;
    }
}
